<template>
  <div class="goods-price-box">
    <div class="goods-price-list">
      <!-- 赠送 -->
      <template v-if="goodsInfo.priceType == 1">
        <div class="red bold">
          <span>赠送</span>
        </div>
        <div class="gray">
          <span>售价：</span>
          <span class="line-through">￥{{ goodsInfo.retailPrice }}</span>
        </div>
      </template>
      <!-- 特价 -->
      <template v-else-if="goodsInfo.priceType == 2">
        <div class="red bold">
          <span>特价：</span>
          <span>￥{{ goodsInfo.specialPrice }}</span>
        </div>
        <div class="gray">
          <span>售价：</span>
          <span class="line-through">￥{{ goodsInfo.retailPrice }}</span>
        </div>
      </template>
      <!-- 折扣 -->
      <template v-else-if="goodsInfo.priceType == 3">
        <div class="red bold">
          <span>售价：</span>
          <span>￥{{ goodsInfo.retailPrice }}</span>
        </div>
        <div class="red bold">
          <span>{{ goodsInfo.priceLabel }}</span>
        </div>
      </template>
      <!-- 满减 -->
      <template v-else-if="goodsInfo.priceType == 4">
        <div class="red bold">
          <span>售价：</span>
          <span>￥{{ goodsInfo.retailPrice }}</span>
        </div>
        <div class="red bold">
          <span>{{ goodsInfo.priceLabel }}</span>
        </div>
      </template>
      <!-- 无活动 -->
      <template v-else>
        <div class="red bold">
          <span>售价：</span>
          <span class="bold">￥{{ goodsInfo.retailPrice }}</span>
        </div>
      </template>
    </div>
    <div class="goods-price-list">
      <div class="red bold">
        <span>会员价：</span>
        <span class="bold">￥{{ goodsInfo.vipPrice }}</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "priceItem",
  props: {
    goodsItem: {
      type: [Object],
      default: () => {},
    },
  },

  computed: {
    goodsInfo() {
      const item = { ...this.goodsItem };
      if (!item.vipPrice) {
        item.vipPrice = item.retailPrice;
      }
      item.priceType = 0;
      if (item.giftWare) {
        item.priceType = 1; // 赠送
        item.priceLabel = "赠送";
      } else if (item.specialPrice) {
        item.priceType = 2; // 特价
      } else if (item.discountRate) {
        item.priceType = 3; // 折扣
        let discountRate;
        if ((item.discountRate * 100) % 10) {
          discountRate = item.discountRate * 100;
        } else {
          discountRate = item.discountRate * 10;
        }
        item.priceLabel = "打" + discountRate + "折";
      } else if (item.min && item.reductionPrice) {
        item.priceType = 4; // 满减
        item.priceLabel = "满" + item.min + "减" + item.reductionPrice;
      }
      return item;
    },
  },
};
</script>
<style lang="scss" scoped>
.goods-price-box {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  font-size: 12px;
  width: 100%;
  height: 100%;
  flex-grow: 1;
}
.goods-price-list {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  .bold {
    font-weight: bold;
  }
  .red {
    color: #ff5b57;
  }
  .gray {
    color: gray;
  }
  .line-through {
    text-decoration: line-through;
  }
}
</style>
